package com.team.controller;

import com.team.entity.Admin;
import com.team.result.Result;
import com.team.service.TestService;
import com.team.utils.AliOssUtil;
import com.team.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class testController
    {
        //阿里云的使用
        @Autowired
        private AliOssUtil aliOssUtil;
        //jwt令牌的使用
        @Autowired
        private JwtUtil jwtUtil;
        @Autowired
        private TestService testService;
        @PostMapping("/upload")
        public Result<String> upload(@RequestBody MultipartFile image) throws IOException
            {
            String url = aliOssUtil.upload(image);
            return Result.success(url);

        }

        @GetMapping("/jwt")
        public Result<String> getJwt(String name,String password){

            Map<String, Object> claims=new HashMap<>();
            claims.put("name",name);
            claims.put("password",password);
            String jwt = jwtUtil.getJwt(claims);
            return Result.success(jwt);

        }

        @GetMapping("/admin")
        public Result<List<Admin>> getAdmin(){
            List<Admin> test = testService.test();
            System.out.println(test);
            return Result.success(test);
        }
    }
